package com.briup.smartcity.service.impl;

import com.briup.smartcity.bean.Carousel;
import com.briup.smartcity.bean.Category;
import com.briup.smartcity.exception.ServiceException;
import com.briup.smartcity.mapper.CategoryMapper;

import com.briup.smartcity.mapper.extend.CarouselExtendMapper;
import com.briup.smartcity.mapper.extend.CategoryExtendMapper;
import com.briup.smartcity.service.ICategoryService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;
@Service
public class CategoryServiceImpl implements ICategoryService {
    @Autowired
    private CategoryMapper mapper;
    @Autowired// ioc 容器
    private CategoryExtendMapper extendMapper;//=null


    @Override
    public PageInfo<Category> pageQueryAll(int pageNum, int pageSize) throws ServiceException {

        PageHelper.startPage(pageNum,pageSize);

        List<Category> list = extendMapper.findAllCategory();

        return new PageInfo<>(list);

    }

    @Override
    public void deleteById(int id) throws ServiceException {
    mapper.deleteByPrimaryKey(id);
    }

    @Override
    public void batchDelete(int[] ids) throws ServiceException {
    for (int id:ids){
        mapper.deleteByPrimaryKey(id);
    }
    }

    @Override
    public void saveCategory(Category category) throws ServiceException {
    mapper.insertSelective(category);
    }



    @Override
    public void updateCategory(Category category) throws ServiceException {

    mapper.updateByPrimaryKeySelective(category);

    }

    @Override
    public List<Category> findAll() throws ServiceException {
    List<Category> all = extendMapper.findAllCategory();
    return all;
    }


}
